import { Controller, Get, Post, Put, Delete, Body, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { H5Service } from './h5.service';
import { PaginationDto } from '@app/common';

@ApiTags('H5应用管理')
@Controller()
export class H5Controller {
  constructor(private readonly h5Service: H5Service) { }

  @Get('config')
  @ApiOperation({ summary: '获取H5配置' })
  @ApiResponse({ status: 200, description: '获取配置成功' })
  getConfig() {
    return this.h5Service.getConfig();
  }

  @Get('config/:key')
  @ApiOperation({ summary: '根据键获取配置' })
  @ApiResponse({ status: 200, description: '获取配置成功' })
  getConfigByKey(@Param('key') key: string) {
    return this.h5Service.getConfigByKey(key);
  }

  @Post('config')
  @ApiOperation({ summary: '创建配置' })
  @ApiResponse({ status: 201, description: '创建配置成功' })
  createConfig(@Body() config: any) {
    return this.h5Service.createConfig(config);
  }

  @Put('config/:id')
  @ApiOperation({ summary: '更新配置' })
  @ApiResponse({ status: 200, description: '更新配置成功' })
  updateConfig(@Param('id') id: string, @Body() config: any) {
    return this.h5Service.updateConfig(+id, config);
  }

  @Delete('config/:id')
  @ApiOperation({ summary: '删除配置' })
  @ApiResponse({ status: 200, description: '删除配置成功' })
  deleteConfig(@Param('id') id: string) {
    return this.h5Service.deleteConfig(+id);
  }

  @Get('users')
  @ApiOperation({ summary: '获取H5用户列表' })
  @ApiResponse({ status: 200, description: '获取用户列表成功' })
  getUsers(@Query() paginationDto: PaginationDto) {
    return this.h5Service.getUsers(paginationDto);
  }

  @Get('users/:id')
  @ApiOperation({ summary: '获取H5用户详情' })
  @ApiResponse({ status: 200, description: '获取用户详情成功' })
  getUser(@Param('id') id: string) {
    return this.h5Service.getUser(+id);
  }

  @Post('users')
  @ApiOperation({ summary: '创建H5用户' })
  @ApiResponse({ status: 201, description: '创建用户成功' })
  createUser(@Body() user: any) {
    return this.h5Service.createUser(user);
  }

  @Put('users/:id')
  @ApiOperation({ summary: '更新H5用户' })
  @ApiResponse({ status: 200, description: '更新用户成功' })
  updateUser(@Param('id') id: string, @Body() user: any) {
    return this.h5Service.updateUser(+id, user);
  }

  @Delete('users/:id')
  @ApiOperation({ summary: '删除H5用户' })
  @ApiResponse({ status: 200, description: '删除用户成功' })
  deleteUser(@Param('id') id: string) {
    return this.h5Service.deleteUser(+id);
  }
}
